package com.heima.article.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.AuthorMapper;
import com.heima.article.service.AuthorService;
import com.heima.common.exception.CustomException;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import org.springframework.stereotype.Service;

@Service
public class AuthorServiceImpl extends ServiceImpl<AuthorMapper, ApAuthor> implements AuthorService {

    /**
     * 根据id查询作者信息
     */
    @Override
    public ResponseResult findAuthorById(Long id) {
        if (id == null) {
            CustomException.cust(AppHttpCodeEnum.PARAM_INVALID);
        }
        ApAuthor apAuthor = getById(id);
        if (apAuthor == null) {
            return ResponseResult.okResult(null);
        }
        CustomException.cust(AppHttpCodeEnum.DATA_NOT_EXIST);
        return null;
    }

    /**
     * 新增作者信息
     */
    @Override
    public ResponseResult addAuthor(ApAuthor apAuthor) {
        if (apAuthor == null) {
            CustomException.cust(AppHttpCodeEnum.PARAM_INVALID);
        }
        save(apAuthor);
        return ResponseResult.okResult();
    }
}
